//// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
//package com.linqingying.gitcode.pullrequest.ui.list
//
//import com.intellij.collaboration.async.combineAndCollect
//import com.intellij.collaboration.async.launchNow
//import com.intellij.collaboration.async.nestedDisposable
//import com.intellij.collaboration.ui.CollaborationToolsUIUtil.wrapWithProgressStripe
//import com.intellij.collaboration.ui.VerticalListPanel
//import com.intellij.collaboration.ui.codereview.list.ReviewListUtil.wrapWithLazyVerticalScroll
//import com.intellij.ide.DataManager
//import com.intellij.openapi.actionSystem.ActionManager
//import com.intellij.openapi.project.Project
//import com.intellij.ui.ScrollableContentBorder
//import com.intellij.ui.Side
//import com.intellij.ui.components.ActionLink
//import com.intellij.ui.components.JBList
//import com.intellij.ui.components.panels.Wrapper
//import com.intellij.ui.scale.JBUIScale
//import com.intellij.util.ui.JBUI
//import com.intellij.util.ui.UIUtil
//import kotlinx.coroutines.CoroutineScope
//import com.linqingying.gitcode.api.data.pullrequest.GCPullRequestShort
//import com.linqingying.gitcode.i18n.GitCodeBundle
//import com.linqingying.gitcode.pullrequest.GCPRListViewModel
//import com.linqingying.gitcode.pullrequest.action.GCPRActionKeys
//import com.linqingying.gitcode.pullrequest.ui.filters.GCPRSearchPanelFactory
//import com.linqingying.gitcode.ui.avatars.GCAvatarIconsProvider
//import java.awt.FlowLayout
//import javax.swing.JComponent
//import javax.swing.JLabel
//import javax.swing.JPanel
//
//internal class GCPRListPanelFactory(private val project: Project, private val listVm: GCPRListViewModel) {
//
//  fun create(cs: CoroutineScope, list: JBList<GCPullRequestShort>, avatarIconsProvider: GCAvatarIconsProvider): JComponent {
//    val actionManager = ActionManager.getInstance()
//    val searchPanel = GCPRSearchPanelFactory(listVm.searchVm, avatarIconsProvider).create(cs)
//
//    val outdatedStatePanel = JPanel(FlowLayout(FlowLayout.LEFT, JBUIScale.scale(5), 0)).apply {
//      background = UIUtil.getPanelBackground()
//      border = JBUI.Borders.empty(4, 0)
//      add(JLabel(GitCodeBundle.message("pull.request.list.outdated")))
//      add(ActionLink(GitCodeBundle.message("pull.request.list.refresh")) {
//        listVm.refresh()
//      })
//
//      isVisible = false
//    }
//
//    cs.launchNow {
//      combineAndCollect(listVm.loading, listVm.error, listVm.outdated) { loading, error, outdated ->
//        outdatedStatePanel.isVisible = outdated && (!loading && error == null)
//      }
//    }
//
//    val controlsPanel = VerticalListPanel().apply {
//      add(searchPanel)
//      add(outdatedStatePanel)
//    }
//
//    val listLoaderPanel = wrapWithLazyVerticalScroll(cs, list, listVm::requestMore)
//    val listWrapper = Wrapper()
//    val progressStripe = wrapWithProgressStripe(cs, listVm.loading, listWrapper)
//    ScrollableContentBorder.setup(listLoaderPanel, Side.TOP, progressStripe)
//
//    GCPRListPanelController(project, cs, listVm, list.emptyText, listLoaderPanel, listWrapper)
//
//    return JBUI.Panels.simplePanel(progressStripe).addToTop(controlsPanel).andTransparent().also {
//      val listController = GCPRListControllerImpl(listVm)
//      DataManager.registerDataProvider(it) { dataId ->
//        when {
//          GCPRActionKeys.PULL_REQUESTS_LIST_CONTROLLER.`is`(dataId) -> listController
//          GCPRActionKeys.PULL_REQUEST_ID.`is`(dataId) -> list.selectedValue?.prId
//          GCPRActionKeys.PULL_REQUEST_URL.`is`(dataId) -> list.selectedValue?.url
//          else -> null
//        }
//      }
//      actionManager.getAction("GitCode.PullRequest.List.Reload").registerCustomShortcutSet(it, cs.nestedDisposable())
//    }
//  }
//}
